<template>
  <div class="view">
    <div class="search-header">
      <el-form :inline="true">
        <el-form-item label="状态">
          <el-select
            v-model="queryParams.useType"
            placeholder="请选择使用状态"
            clearable
          >
            <el-option
              v-for="dict in coupon_use_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button color="#1aa684" icon="Search" @click="handleQuery"
            >搜索
          </el-button>
          <el-button color="#1aa684" plain icon="Refresh" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="list">
      <el-table-column type="selection" width="55" />
      <!--      <el-table-column label="优惠券ID" prop="id" width="300"></el-table-column>-->
      <el-table-column label="图片">
        <template #default="scope">
          <image-preview
            :src="scope.row.couponImg"
            :width="50"
            :height="50"
          ></image-preview>
        </template>
      </el-table-column>
      <el-table-column label="使用门槛" prop="minPoint" align="center">
        <template #default="scope">
          <span v-if="scope.row.minPoint === 0.0" style="color: #53bc0d"
            >无门槛</span
          >
          <span v-else>{{ scope.row.minPoint }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="金额" prop="amount" align="center">
        <template #default="scope">
          <span style="color: #f15d5dff">{{ scope.row.amount }}</span> 元
        </template>
      </el-table-column>
      <el-table-column label="获取方式" align="center" prop="getType">
        <template #default="scope">
          <dict-tag :options="coupon_get_type" :value="scope.row.getType" />
        </template>
      </el-table-column>
      <el-table-column label="使用状态" align="center" prop="useType">
        <template #default="scope">
          <dict-tag :options="coupon_use_status" :value="scope.row.useStatus" />
        </template>
      </el-table-column>
      <el-table-column
        label="使用时间"
        align="center"
        prop="useTime"
        width="180"
      >
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script setup>
import { listUserCouponHistory } from "@/api/mall/client/points/coupon";
const { proxy } = getCurrentInstance();
const { coupon_use_type, coupon_get_type, coupon_use_status } = proxy.useDict(
  "coupon_use_type",
  "coupon_use_status",
  "coupon_get_type"
);
const list = ref([]);
const total = ref(0);
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  useType: undefined,
});
const getList = async () => {
  const res = await listUserCouponHistory(queryParams.value);
  list.value = res.rows;
  total.value = res.total;
};
getList();
/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};
/** 重置按钮操作 */
const resetQuery = () => {
  proxy.resetForm("queryRef");
  handleQuery();
};
</script>

<style lang="scss" scoped>
:deep(.el-pagination) {
  --el-pagination-hover-color: #1aa684;
  --el-color-primary: #1aa684;
}
:deep(.el-select-dropdown__item.selected) {
  color: #1aa684 !important;
}
.el-select {
  --el-select-input-hover-border-color: #1aa684;
  --el-select-input-focus-border-color: #1aa684;
  --el-color-primary: #1aa684 !important;
}
:deep(.el-select-dropdown) {
  --el-color-primary: #1aa684 !important;
}
:deep(.selected) {
  color: #1aa684 !important;
}

:deep(.el-select-dropdown__item.selected) {
  color: #1aa684 !important;
}
</style>
